package com.epic.quartz;

import com.epic.inter.ITask;
import com.epic.po.quartz.TaskInfo;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BaseTask implements Job {
    private static Logger logger =  LoggerFactory.getLogger(BaseTask.class);

    /**
     *  在这个 封装类 得到对应的Bean，然后执行task方法 类似多态
     * @param jobExecutionContext
     * @throws JobExecutionException
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        TaskInfo taskInfo = (TaskInfo) jobDataMap.get("taskInfo");
        logger.info("job " + taskInfo.getTaskDesc() + " start ");
        try{
            Object iTask = AppUtil.getBean(taskInfo.getTaskBean());
            ((ITask)(iTask)).task();
        }catch (Exception e){
            logger.error(e.getMessage());
        }
        logger.info("job " + taskInfo.getTaskDesc() + " end ");
    }
}
